package com.binc.testspring.controller;

import com.binc.testspring.service.ICustomerService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Copyright (C), 2019-2021, XXX 奇限公司
 * FileName: ReplaceAutowiredController
 *
 * Autho: binC
 * Date:  2021/10/29 14:01
 * Description: 尝试用@RequiredArgsConstructor 替换常用的Autowired
 * <p>这是lombok的注解，也就是说class会自动生成一些东西的{@code
 * package com.binc.testspring.controller;
 *
 * import com.binc.testspring.service.ICustomerService;
 * import org.springframework.web.bind.annotation.GetMapping;
 * import org.springframework.web.bind.annotation.RestController;
 *
 * @RestController("/replace")
 * public class ReplaceAutowiredController {
 *     final ICustomerService customerService;
 *
 *     @GetMapping
 *     public String helloWorld() {
 *         String s = this.customerService.helloWorld();
 *         return s;
 *     }
 *
 *     public ReplaceAutowiredController(final ICustomerService customerService) {   这里就是@RequiredArgsConstructor 利用构造器诸如生成的代码；
 *     //这样做的好处是放置一个极端情况
 *          @Autowired
 *          private User user;
 *
 *          private String company;
 *
 *              public UserDaoImpl(){
 *              this.company = user.getCompany();
 *              }
 *     //Java 在初始化一个类时，是按照静态变量或静态语句块 –> 实例变量或初始化语句块 –> 构造方法 -> @Autowired 的顺序。所以在执行这个类的构造方法时，user对象尚未被注入，它的值还是 null。
 *         this.customerService = customerService;
 *     }
 * }
 * }
 * </p>
 *
 * History:
 * <author>     <time>      <version>       <desc>
 * 作者姓名       修改时间      版本          描述
 */
@RestController("/replace")
@RequiredArgsConstructor
public class ReplaceAutowiredController {

    final ICustomerService customerService; //注意一定要用final标注；

    @GetMapping
    public String helloWorld(){

        String s = customerService.helloWorld();
        return s;
    }


}
